<?php
            
use app\model\Theme; 


/**
 * Author: cbw
 * Desc: 教培
 * Time: 2021/11/15 3:02 下午
 * Email: 17854288794@163.com
 */
class Setting_Page extends PluginWebPage {
    function main()
    {
        global $_G,$_P,$_S,$_C;
        if (!$_G['isSuperAdmin']){
            return_msg('非法请求');
            die();
        }
        $action = $_P['action']?$_P['action']:7;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $item = EducationModel::getRewardByWhere(['themeid'=>$themeid]);
        $item['tuan'] = json_decode($item['tuan'],true);
        $item['order'] = json_decode($item['order'],true);
        $item['colors'] = json_decode($item['colors'],true);
        $item['other_name'] = json_decode($item['other_name'],true);
        $open_shangjia_rules = $item['open_shangjia_rules'];
        $btm_img = $item['btm_img'];
        $item_order_count = count($item['order']);
        $now = time();

        $name = isset($_P['name'])?trim($_P['name']):'';
        $page_index = max(1,intval($_P['page']));
        $page_size = 10;
        $page_start = ($page_index-1)*$page_size;
        $shangjiaid = isset($_P['shangjiaid'])?$_P['shangjiaid']:0;
        $shangjia = EducationModel::getShangjiaList();
        array_unshift($shangjia,['id'=>0,'name'=>'全部商家']);
        $gifts = EducationModel::getGiftList($themeid,$shangjiaid,$name,0,0);
        $list = EducationModel::getGiftList($themeid,$shangjiaid,$name,$page_start,$page_size);
        $coupon_lists = EducationModel::getCouponList($themeid,$shangjiaid,$name,0,0);
        $coupon_list = EducationModel::getCouponList($themeid,$shangjiaid,$name,$page_start,$page_size);
        //最早一条优惠券记录
        $first_coupon_item = EducationModel::getFirstCoupon($themeid);

        $other_config = json_decode($item['other_config'],true);
        $school_other_name = $other_config['school_other_name'];
        $course_other_name = $other_config['course_other_name'];
        $gift_other_name = $other_config['gift_other_name'];
        $open_position = $other_config['open_position'];
        $open_shangjia_video = $other_config['open_shangjia_video'];
        $show_buy_total = $other_config['show_buy_total'];
        $scrool_icon_show = $other_config['scrool_icon_show'];
        $edu_pageshare_txt = $other_config['edu_pageshare_txt'];
        $edu_share_tips = isset($other_config['edu_share_tips'])?$other_config['edu_share_tips']:'请点击右上角[发送到朋友圈]';
        $edu_share_img = isset($other_config['edu_share_img'])?$other_config['edu_share_img']:"";
        //定位相关
        $edu_location_img = isset($other_config['edu_location_img'])?$other_config['edu_location_img']:'';
        $edu_location_tips = isset($other_config['edu_location_tips'])?$other_config['edu_location_tips']:'';
        $edu_location_tips_font_size = isset($other_config['edu_location_tips_font_size'])?$other_config['edu_location_tips_font_size']:'';
        $edu_location_tips_color = isset($other_config['edu_location_tips_color'])?$other_config['edu_location_tips_color']:'';
        $edu_location_bg_color = isset($other_config['edu_location_bg_color'])?$other_config['edu_location_bg_color']:'';
        $edu_success_location_tips = isset($other_config['edu_success_location_tips'])?$other_config['edu_success_location_tips']:'';
        $edu_location_show = isset($other_config['edu_location_show'])?$other_config['edu_location_show']:1;
        $tabcar_ac_info = isset($other_config['tabcar_ac_info'])?$other_config['tabcar_ac_info']:1;
        $tabcar_course_info = isset($other_config['tabcar_course_info'])?$other_config['tabcar_course_info']:1;
        $tabcar_gift_info = isset($other_config['tabcar_gift_info'])?$other_config['tabcar_gift_info']:1;
        $education_acBar_c1_open = isset($other_config['education_acBar_c1_open'])?$other_config['education_acBar_c1_open']:1;

        $tabcar_activity_name = $other_config['tabcar_activity_name'];
        $tabcar_course_name = $other_config['tabcar_course_name'];
        $tabcar_gift_name = $other_config['tabcar_gift_name'];

        $gift_unlock_min_num = $other_config['gift_unlock_min_num'];
        $gift_unlock_max_num = $other_config['gift_unlock_max_num'];
        $lock_gift_mode = $other_config['lock_gift_mode'];
        $lock_gift_type = $other_config['lock_gift_type'];
        $gift_none_btn_txt = $other_config['gift_none_btn_txt']?$other_config['gift_none_btn_txt']:'免费获取';
        $gift_has_btn_txt = $other_config['gift_has_btn_txt']?$other_config['gift_has_btn_txt']:'已获取';
        $open_tuan_other_name = $other_config['open_tuan_other_name']?$other_config['open_tuan_other_name']:'开团成功';

        $company_list_show = $other_config['company_list_show']?$other_config['company_list_show']:1;
        $pn_wxapp = $_S['pn_wxapp'];
        $total = $page_total = count($coupon_lists);
        $pager = pagination($page_total,$page_index,$page_size);
        if ($action==72){
            $temp_theme = self::getTempTheme();
            $return_clicent = get_defined_vars();
return $this->view('/education/setting/style', $return_clicent);
        }else{
            $return_clicent = get_defined_vars();
return $this->view('/education/setting/main', $return_clicent);
        }
    }

    function edit()
    {
        return $this->post();
    }
    protected function post()
    {
        global $_G, $_P;
        $action = 6;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        if (!$themeid){
            show_json(0,'活动入口不正确');
            return;
        }
        if (!$_G['isSuperAdmin']){
            show_json(0,'非法请求');
            die();
        }

        if ($_G['ispost'] && $themeid ) {
            $op = $_P['op'];
            $item = EducationModel::getRewardByWhere(['themeid'=>$themeid]);
            //通用化设置
            if ($op=='common_setting'){
                $shangjia_rules = [];
                $shangjia_rule_ids = $_P['shangjia_rule_id'];
                $shangjia_rule_sort = $_P['shangjia_rule_sort'];
                $shangjia_rule_content = $_P['shangjia_rule_content'];
                $shangjia_rule_special = $_P['shangjia_rule_special'];
                if (is_array($shangjia_rule_ids)){
                    foreach ($shangjia_rule_ids as $k =>$v){
                        $dd = ['shangjia_rule_id'=>$v,'rule_content'=>$shangjia_rule_content[$k],'rule_sort'=>$shangjia_rule_sort[$k],'rule_special'=>$shangjia_rule_special[$k]];
                        $shangjia_rules[] = $dd;
                    }
                }
                $edu_pageshare_txt = $_P['edu_pageshare_txt']?$_P['edu_pageshare_txt']:'';
//                二次定位
                $edu_location_img = $_P['edu_location_img']?tomedia($_P['edu_location_img']):'http://img2020.yixuansoft.cn/images/2/2022/07/qCMkMM1r78zVL4zsxS00sGgv4MGsm1.png';//定位图标
                $edu_location_tips = $_P['edu_location_tips']?$_P['edu_location_tips']:'设置家的位置';
                $edu_location_show = $_P['edu_location_show']?$_P['edu_location_show']:1;//定位图标显示条件
                $edu_success_location_tips = $_P['edu_success_location_tips']?$_P['edu_success_location_tips']:'重新设置位置';//定位图标显示条件
                $edu_location_tips_font_size = $_P['edu_location_tips_font_size']?$_P['edu_location_tips_font_size']:'14';
                $edu_location_tips_color = $_P['edu_location_tips_color']?$_P['edu_location_tips_color']:'#000000';
                $edu_location_bg_color = $_P['edu_location_bg_color']?$_P['edu_location_bg_color']:'#f0f0f0';
                $open_position = intval($_P['open_position']);
                $gift_unlock_min_num = max(1,$_P['gift_unlock_min_num']);
                $gift_unlock_max_num = max(1,$_P['gift_unlock_max_num']);
                $item_old_other_config = json_decode($item['other_config'],true);
                $new_other_config = [
                    'open_position'=>$open_position,
                    'open_shangjia_video'=>(int)$_P['open_shangjia_video'],
                    'edu_pageshare_txt'=>$edu_pageshare_txt,
                    'edu_location_img'=>$edu_location_img,
                    'edu_location_show'=>$edu_location_show,
                    'edu_success_location_tips'=>$edu_success_location_tips,
                    'edu_location_tips'=>$edu_location_tips,
                    'edu_location_tips_font_size'=>$edu_location_tips_font_size,
                    'edu_location_tips_color'=>$edu_location_tips_color,
                    'edu_location_bg_color'=>$edu_location_bg_color,
                    'edu_share_tips'=>$_P['edu_share_tips']?$_P['edu_share_tips']:'请点击右上角[发送到朋友圈],即可收到现金红包，朋友报名还可收到红包',
                    'edu_share_img'=>$_P['edu_share_img']?tomedia($_P['edu_share_img']):'',
                    'tabcar_ac_info'=>$_P['tabcar_ac_info']?intval($_P['tabcar_ac_info']):1,
                    'gift_unlock_min_num'=>(int)$gift_unlock_min_num,
                    'gift_unlock_max_num'=>(int)$gift_unlock_max_num,
                    'lock_gift_mode'=>(int)$_P['lock_gift_mode'],
                    'lock_gift_type'=>(int)$_P['lock_gift_type'],
                ];
                $other_config = json_encode(array_merge($item_old_other_config,$new_other_config));
                //员工提成设置
                $group_min_out_price = isset($_P['group_min_out_price'])?$_P['group_min_out_price']:0;
                $group_max_out_price = isset($_P['group_max_out_price'])?$_P['group_max_out_price']:0;
                $min_out_price = isset($_P['min_out_price'])?$_P['min_out_price']:0;
                $max_out_price = isset($_P['max_out_price'])?$_P['max_out_price']:0;
                if ($group_min_out_price>$group_max_out_price){
                    show_json(0,'团长提成不合法');
                    return;
                }
                if ($min_out_price>$max_out_price){
                    show_json(0,'团员提成不合法');
                    return;
                }
                //购买设置
                $course_min_num = $_P['course_min_num']?$_P['course_min_num']:1;
                $course_max_num = $_P['course_max_num']?$_P['course_max_num']:1;
                $gift_min_num = $_P['gift_min_num']?$_P['gift_min_num']:1;
                $gift_max_num = $_P['gift_max_num']?$_P['gift_max_num']:1;
                if ($course_min_num>$course_max_num){
                    show_json(0,'可选课程数不合法');
                    return;
                }
                if ($gift_min_num>$gift_max_num){
                    show_json(0,'可选赠品数不合法');
                    return;
                }

                $btm_img = tomedia($_P['btm_img']);
                $update_arr = [
                    'poster_show'=>$_P['poster_show'],
                    'send_gift_type'=>isset($_P['send_gift_type'])?$_P['send_gift_type']:1,//邀请礼发放条件
                    'other_config'=>$other_config,
                    'group_min_out_price'=>$group_min_out_price,
                    'group_max_out_price'=>$group_max_out_price,
                    'min_out_price'=>$min_out_price,
                    'max_out_price'=>$max_out_price,
                    'course_min_num'=>$course_min_num,
                    'course_max_num'=>$course_max_num,
                    'gift_min_num'=>$gift_min_num,
                    'gift_max_num'=>$gift_max_num,
                    'btm_img'=>$btm_img,
                ];
                if (!$item){
                    $update_arr['themeid']=$themeid;
                    $res = EducationModel::insertReward($update_arr);
                }else{
                    $res = EducationModel::editReward(['themeid'=>$themeid],$update_arr);
                }
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //样式设置
            if ($op=='common_style_setting'){
                $show_buy_total = isset($_P['show_buy_total'])?(int)$_P['show_buy_total']:2;
                //别名
                $other_name = [
                    'flag_name'=>$_P['flag_name']?$_P['flag_name']:'福利领取记录',
                    'activity_name'=>$_P['activity_name']?$_P['activity_name']:'活动火热进行中',
                    'djs_name'=>$_P['djs_name']?$_P['djs_name']:'活动倒计时',
                ];
                $color_arr = [
                    'temp_theme'=>$_P['temp_theme']?$_P['temp_theme']:0,//主题颜色
                    'font_color'=>$_P['font_color']?$_P['font_color']:'#FF600A',//主题字体颜色
                    'getLi_c'=>$_P['getLi_c']?$_P['getLi_c']:'#fff7f3',//福利领取记录背景色
                    'acBar_c1'=>$_P['acBar_c1']?$_P['acBar_c1']:'#fff3f3',//页面活动信息板块渐变颜色1
                    'acBar_c2'=>$_P['acBar_c2']?$_P['acBar_c2']:'#ffffff',//页面活动信息板块渐变颜色2
                    'acPeo_c'=>$_P['acPeo_c']?$_P['acPeo_c']:'#ffdecd',//活动倒计时 边框颜色
                    'acBar_c_bak'=>$_P['acBar_c_bak']?$_P['acBar_c_bak']:'#ffffff',//活动倒计时 背景颜色
                    'hotAc_c'=>$_P['hotAc_c']?$_P['hotAc_c']:'#ffdecd',//活动火热进行中 边框颜色
                    'shop_logo_c'=>$_P['shop_logo_c']?$_P['shop_logo_c']:'#f3590f',//商家联盟logo边框色
                    'shop_item_c'=>$_P['shop_item_c']?$_P['shop_item_c']:'#fff8f3',//商家联盟商家信息背景色
                    'shop_card_c1'=>$_P['shop_card_c1']?$_P['shop_card_c1']:'#fd8c0c',//商家联盟图片卡轮播 渐变色1
                    'shop_card_c2'=>$_P['shop_card_c2']?$_P['shop_card_c2']:'#ff4714',//商家联盟图片卡轮播 渐变色2
                    'acCho_c1'=>$_P['acCho_c1']?$_P['acCho_c1']:'#FF8E0D',//选项卡背景色1
                    'acCho_c2'=>$_P['acCho_c2']?$_P['acCho_c2']:'#FF5005',//选项卡背景色2
                    'lcc_c1'=>$_P['lcc_c1']?$_P['lcc_c1']:'#f5f6f7',//课程展示 未选中背景色1
                    'lcc_c2'=>$_P['lcc_c2']?$_P['lcc_c2']:'#f5f6f7',//课程展示 未选中背景色2
                    'lcc_tc'=>$_P['lcc_tc']?$_P['lcc_tc']:'#999999',//课程展示 未选中文字颜色
                    'lcc_c_c1'=>$_P['lcc_c_c1']?$_P['lcc_c_c1']:'#ffffff',//课程展示 选中背景色1
                    'lcc_c_c2'=>$_P['lcc_c_c2']?$_P['lcc_c_c2']:'#ffffff',//课程展示 选中背景色2
                    'lcc_c_tc'=>$_P['lcc_c_tc']?$_P['lcc_c_tc']:'#999999',//课程展示 选中文字颜色
                ];
                //判断当前主题色与保存主题色不一致 执行主题色覆盖
                $config_colors = json_decode($item['colors'],true);
                if ($config_colors && $config_colors['temp_theme'] && $config_colors['temp_theme']!=$_P['temp_theme']){

                }
                $school_other_name = $_P['school_other_name']?$_P['school_other_name']:'校区';
                $course_other_name = $_P['course_other_name']?$_P['course_other_name']:'课程';
                $gift_other_name = $_P['gift_other_name']?$_P['gift_other_name']:'赠品';
                $open_tuan_other_name = $_P['open_tuan_other_name']?$_P['open_tuan_other_name']:'开团成功';
                $education_acBar_c1_open = $_P['education_acBar_c1_open'];
                $tabcar_activity_name = $_P['tabcar_activity_name']?$_P['tabcar_activity_name']:'活动介绍';
                $tabcar_course_name = $_P['tabcar_course_name']?$_P['tabcar_course_name']:'课程展示';
                $tabcar_gift_name = $_P['tabcar_gift_name']?$_P['tabcar_gift_name']:'解锁福利';
                $course_style = $_P['course_style']?$_P['course_style']:1;
                $open_shangjia_rules = 0;
                if ($course_style==3 || $course_style==4){
                    $open_shangjia_rules = 1;
                }
                $gift_none_btn_txt = $_P['gift_none_btn_txt']?$_P['gift_none_btn_txt']:'免费获取';
                $gift_has_btn_txt = $_P['gift_has_btn_txt']?$_P['gift_has_btn_txt']:'已获取';
                $gift_index_none_btn_txt = $_P['gift_index_none_btn_txt']?$_P['gift_index_none_btn_txt']:'报名解锁';
                $gift_index_has_btn_txt = $_P['gift_index_has_btn_txt']?$_P['gift_index_has_btn_txt']:'已领取';

                $item_old_other_config = json_decode($item['other_config'],true);
                $new_other_config = [
                    'show_buy_total'=>$show_buy_total,
                    'school_other_name'=>$school_other_name,
                    'course_other_name'=>$course_other_name,
                    'gift_other_name'=>$gift_other_name,
                    'open_tuan_other_name'=>$open_tuan_other_name,
                    'education_acBar_c1_open'=>$education_acBar_c1_open,
                    'scrool_icon_show'=>(int)$_P['scrool_icon_show'],
                    'company_list_show'=>$_P['company_list_show'],
                    'tabcar_activity_name'=>$tabcar_activity_name,
                    'tabcar_course_info'=>$_P['tabcar_course_info']?intval($_P['tabcar_course_info']):1,
                    'tabcar_course_name'=>$tabcar_course_name,
                    'tabcar_gift_info'=>$_P['tabcar_gift_info']?intval($_P['tabcar_gift_info']):1,
                    'tabcar_gift_name'=>$tabcar_gift_name,
                    'gift_none_btn_txt'=>$gift_none_btn_txt,
                    'gift_has_btn_txt'=>$gift_has_btn_txt,
                    'gift_index_none_btn_txt'=>$gift_index_none_btn_txt,
                    'gift_index_has_btn_txt'=>$gift_index_has_btn_txt,
                ];
                $other_config = json_encode(array_merge($item_old_other_config,$new_other_config));

//                $other_config = json_encode([
//                    'show_buy_total'=>$show_buy_total,
//                    'school_other_name'=>$school_other_name,
//                    'course_other_name'=>$course_other_name,
//                    'gift_other_name'=>$gift_other_name,
//                    'open_tuan_other_name'=>$open_tuan_other_name,
//                    'education_acBar_c1_open'=>$education_acBar_c1_open,
//                    'scrool_icon_show'=>(int)$_P['scrool_icon_show'],
//                    'company_list_show'=>$_P['company_list_show'],
//                    'tabcar_activity_name'=>$tabcar_activity_name,
//                    'tabcar_course_info'=>$_P['tabcar_course_info']?intval($_P['tabcar_course_info']):1,
//                    'tabcar_course_name'=>$tabcar_course_name,
//                    'tabcar_gift_info'=>$_P['tabcar_gift_info']?intval($_P['tabcar_gift_info']):1,
//                    'tabcar_gift_name'=>$tabcar_gift_name,
//                    'gift_none_btn_txt'=>$gift_none_btn_txt,
//                    'gift_has_btn_txt'=>$gift_has_btn_txt,
//                    'gift_index_none_btn_txt'=>$gift_index_none_btn_txt,
//                    'gift_index_has_btn_txt'=>$gift_index_has_btn_txt,
//                ]);
                $update_arr = [
                    'other_config'=>$other_config,
                    'btn_style'=>$_P['btn_style'],
                    'float_icon_show'=>$_P['float_icon_show'],
                    'flag_show'=>$_P['flag_show'],
                    'other_name'=>json_encode($other_name),
                    'colors'=>json_encode($color_arr),
                    'djs_show'=>$_P['djs_show'],
                    'activity_show'=>$_P['activity_show'],
                    'company_show'=>$_P['company_show'],
                    'course_style'=>$course_style,
                    'open_shangjia_rules'=>$open_shangjia_rules,
                ];
                if (!$item){
                    $update_arr['themeid']=$themeid;
                    $res = EducationModel::insertReward($update_arr);
                }else{
                    $res = EducationModel::editReward(['themeid'=>$themeid],$update_arr);
                }
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //成团奖励设置
            if ($op=='tuan_setting'){
                $gift_id = $_P['gift_id'];
                if (!$gift_id){
                    show_json(0,'成团奖励选择不正确');
                    return;
                }
                $gift = EducationModel::getGiftItemById($themeid,$gift_id);
                $data = [
                    ['key'=>'成团解锁','val'=>'团长专属','type'=>'txt'],
                ];
                $temp_arr1 = ['key'=>'奖品','val'=>$gift['name'],'type'=>'txt'];
                $temp_arr2 = ['key'=>'提供商家','val'=>$gift['shangjia_name'],'type'=>'txt'];
                $temp_arr3 = ['key'=>'主图','val'=>$gift['top_img'],'type'=>'img'];
                $temp_arr4 = ['key'=>'价值','val'=>$gift['price'],'type'=>'txt'];
                $temp_arr5 = ['key'=>'奖励描述','val'=>$gift['detail'],'type'=>'txt'];
                $temp_arr6 = ['key'=>'id','val'=>$gift['id'],'type'=>'txt'];
                array_push($data,$temp_arr1);
                array_push($data,$temp_arr2);
                array_push($data,$temp_arr3);
                array_push($data,$temp_arr4);
                array_push($data,$temp_arr5);
                array_push($data,$temp_arr6);
                if (!$item){
                    $res = EducationModel::insertReward(['tuan'=>json_encode($data),'themeid'=>$themeid]);
                }else{
                    $res = EducationModel::editReward(['themeid'=>$themeid],['tuan'=>json_encode($data)]);
                }
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //删除成团奖励设置
            if ($op=='del_tuan'){
                $res = EducationModel::editReward(['themeid'=>$themeid],['tuan'=>'']);
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //新增解锁奖
            if ($op=='invite_people'){
                $invite_people = intval($_P['invite_people']);
                $invite_desc = trim($_P['invite_desc']);
                $gift_id = intval($_P['gift_id']);
                if (!$invite_people || $invite_people>30){
                    show_json(0,'邀请人数不合法');
                    return;
                }
                if (!$gift_id){
                    show_json(0,'解锁奖品不合法');
                    return;
                }
                if (!$item){
                    $order_list = [];
                }else{
                    if (!$item['order']){
                        $order_list = [];
                    }else{
                        $order_list = json_decode($item['order'],true);
                        if (count($order_list)>=5){
                            show_json(0,'达到解锁奖励上限');
                            return;
                        }
                    }
                }
                $gift_item = EducationModel::getGiftItemById($themeid,$gift_id);
                $temp_arr = ['invite'=>$invite_people,'invite_desc'=>$invite_desc,'img'=>$gift_item['top_img'],'name'=>$gift_item['name'],'price'=>$gift_item['price'],'gift_id'=>$gift_item['id'],'shangjia_name'=>$gift_item['shangjia_name']];
                array_push($order_list,$temp_arr);
                if (!$item){
                    $res = EducationModel::insertReward(['order'=>json_encode($order_list),'themeid'=>$themeid]);
                }else{
                    $res = EducationModel::editReward(['themeid'=>$themeid],['order'=>json_encode($order_list)]);
                }
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //修改解锁奖
            if ($op=='invite_people_edit'){
                $key = $_P['key'];
                if (!$item || ($item && !$item['order'])){
                    show_json(0,'非法操作');
                    return;
                }
                $invite_people = intval($_P['invite_people']);
                $invite_desc = trim($_P['invite_desc']);
                $gift_id = intval($_P['gift_id']);
                $invite_status = intval($_P['invite_status']);
                if (!$invite_people || $invite_people>30){
                    show_json(0,'邀请人数不合法');
                    return;
                }
                if (!$gift_id){
                    show_json(0,'解锁奖品不合法');
                    return;
                }
                $gift_item = EducationModel::getGiftItemById($themeid,$gift_id);
                $temp_arr = ['invite'=>$invite_people,'invite_desc'=>$invite_desc,'img'=>$gift_item['top_img'],
                    'name'=>$gift_item['name'],'price'=>$gift_item['price'],'gift_id'=>$gift_item['id'],'invite_status'=>$invite_status,
                    'shangjia_name'=>$gift_item['shangjia_name']];

                $order_list = json_decode($item['order'],true);
                if (is_array($order_list)){
                    foreach ($order_list as $k => $val)
                    {
                        if ($key==$k){
                            $order_list[$k]=$temp_arr;
                        }
                    }
                    $res = EducationModel::editReward(['themeid'=>$themeid],['order'=>json_encode($order_list)]);
                    if (!$res){
                        show_json(0,['msg'=>'操作失败']);
                    }else{
                        show_json(1,['msg'=>'操作成功']);
                    }
                }
            }
            //删除解锁奖
            if ($op=='del_order_item'){
                $key = $_P['key'];
                if (!$item || ($item && !$item['order'])){
                    show_json(0,'非法操作');
                    return;
                }
                $order_list = json_decode($item['order'],true);
                if (is_array($order_list)){
                    foreach ($order_list as $k => $val)
                    {
                        if ($key==$k){
                            unset($order_list[$k]);
                        }
                    }
                    $res = EducationModel::editReward(['themeid'=>$themeid],['order'=>json_encode($order_list)]);
                    if (!$res){
                        show_json(0,['msg'=>'操作失败']);
                    }else{
                        show_json(1,['msg'=>'操作成功']);
                    }
                }
            }
            //增加\修改渠道优惠券
            if ($op=='add_edit_coupon'){
                $id = $_P['coupon_id'];
                $name = $_P['name'];
                $price = $_P['price'];
                $qty = $_P['qty'];
                $get_start_time = $_P['get_time']['start'];
                $get_end_time = $_P['get_time']['end'];
                $use_start_time = $_P['use_time']['start'];
                $use_end_time = $_P['use_time']['end'];
                $shangjiaid = $_P['shangjiaid'];
                if (!$id){
                    if (!$name || ($name && mb_strlen($name, 'utf-8')>20)){
                        show_json(0,'优惠券名称不合法,限制20字以内');
                        return;
                    }
                    if (!$price){
                        show_json(0,'优惠券金额不合法');
                        return;
                    }
                    if (!$qty){
                        show_json(0,'优惠券数量不合法');
                        return;
                    }
                }

                if ($use_start_time<$get_start_time){
                    show_json(0,'优惠券使用时间不可大于领取时间');
                    return;
                }

                if (!$id){
                    $data = [
                        'shangjiaid'=>$shangjiaid,
                        'name'=>$name,
                        'price'=>$price,
                        'qty'=>$qty,
                        'get_start_time'=>$get_start_time,
                        'get_end_time'=>$get_end_time,
                        'use_start_time'=>$use_start_time,
                        'use_end_time'=>$use_end_time,
                        'themeid'=>$themeid,
                    ];
                    $res =EducationModel::insertCoupon($data);
                }else{
                    $where = ['id'=>$id];
                    $data = [
                        'qty'=>$qty,
                        'get_start_time'=>$get_start_time,
                        'get_end_time'=>$get_end_time,
                        'use_start_time'=>$use_start_time,
                        'use_end_time'=>$use_end_time,
                    ];
                    $res = EducationModel::editCouponItem($where,$data);
                }
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //获取渠道优惠券
            if ($op=='get_coupon'){
                $id = $_P['id'];
                $res = EducationModel::getCoupon($themeid,$id);
                if (!$res){
                    show_json(0,['msg'=>'优惠券不存在']);
                }else{
                    show_json(1,['msg'=>'操作成功','data'=>$res]);
                }
            }
            //删除渠道优惠券
            if ($op=='del_coupon'){
                $id = $_P['id'];
                $where = ['id'=>$id];
                $res1 = EducationModel::getCoupon($themeid,$id);
                if ($res1 && $res1['get_num']){
                    show_json(0,['msg'=>'用户领取的优惠券不可删除']);
                }
                $res = EducationModel::delCouponItem($where);
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
            //修改优惠券的库存
            if($op=='edit_coupon_qty'){
                $id = $_P['coupon_id'];
                $action = $_P['action'];
                $res = EducationModel::getCoupon($themeid,$id);
                $op_qty = $_P['op_qty'];
                $new_qty = 0;
                if ($action=='add'){
                    $new_qty = $res['qty']+$op_qty;
                }else{
                    $new_qty = max(0,($res['qty']-$op_qty));
                    if (($res['get_num']+5)>=$new_qty){
                        show_json(1,['msg'=>'到达库存预警不可减少']);
                    }
                }
                $where = ['id'=>$id];
                $data = [
                    'qty'=>$new_qty,
                ];
                $res = EducationModel::editCouponItem($where,$data);
                if (!$res){
                    show_json(0,['msg'=>'操作失败']);
                }else{
                    show_json(1,['msg'=>'操作成功']);
                }
            }
        }
    }

    protected function getTempTheme()
    {
        return [
            ['title'=>'活力橙','value'=>0],
            ['title'=>'热情红','value'=>1],
//            ['title'=>'萌新粉','value'=>2],
        ];
    }

    protected function getTempColorByVal($val=1)
    {
        switch ($val){
            case 0:
                $color_arr = [
                    'font_color'=>'#FF600A',//主配色
                    'acBar_c1'=>'#FF0505',//金刚区 颜色1
                    'acBar_c2'=>'#FF0505',//金刚区 颜色2
                ];
                break;
            case 1:
                $color_arr = [
                    'font_color'=>'#FF2F0A',
                    'acPeo_c'=>'#EE2727',
                    'hotAc_c'=>'#EE2727',
                    'shop_logo_c'=>'#FF0000',
                    'shop_card_c1'=>'#DA0303',
                    'shop_card_c2'=>'#FF1313',
                    'acCho_c1'=>'#DA0303',
                    'acCho_c2'=>'#FF1313',
                ];
                break;
            case 2:
                $color_arr = [];
                break;
            case 3:
                $color_arr = [];
                break;
            case 4:
                $color_arr = [];
                break;
            case 5:
                $color_arr = [];
                break;
            default:
                $color_arr = [];
                break;
        }
        $color_fixed = [
            'getLi_c'=>'#fff7f3',
            'acBar_c1'=>'#fff3f3',
            'acBar_c2'=>'#FF0505',
            'acBar_c_bak'=>'#ffffff',
            'shop_item_c'=>'#fff8f3',
            'lcc_c1'=>'#f5f6f7',
            'lcc_c2'=>'#f5f6f7',
            'lcc_tc'=>'#999999',
            'lcc_c_c1'=>'#ffffff',
            'lcc_c_c2'=>'#ffffff',
            'lcc_c_tc'=>'#999999',
        ];
        return array_merge($color_arr,$color_fixed);
    }
}